import { RouteRecordRaw } from 'vue-router'

// 前端定义所有可能的动态路由
export const dynamicRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('@/views/layout/Layout.vue'),
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/Dashboard.vue'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'HomeFilled', affix: true,menuCode:'dashboard' }
      }
    ]
  },
    {
        path:'/systemManage',
        component: () => import('@/views/layout/Layout.vue'),
        meta: { title: '系统管理', icon: 'Grid',menuCode:'systemManage' },
        children: [
            {
                path: 'EmployeeManage',
                component: () => import('@/views/systemManage/EmployeeManage.vue'),
                name: 'SystemUser',
                meta: { title: '员工管理', icon: 'Avatar',menuCode:'employeeManage' }
            },
            {
                path: 'MenuManage',
                component: () => import('@/views/systemManage/MenuManagement.vue'),
                name: 'SystemMenu',
                meta: { title: '菜单管理', icon: 'Menu',menuCode:'menuManage' }
            },
            {
              path: 'RoleMenuManage',
              component: () => import('@/views/systemManage/RoleMenuManagement.vue'),
              name: 'SystemRoleMenu',
              meta: { title: '角色菜单管理', icon: 'InfoFilled',menuCode:'roleMenuManage' }
          },
        ]
    },
    {
      path: '/',
      component: () => import('@/views/layout/Layout.vue'),
      redirect: '/PersonalCenter',
      children: [
    {
      path: 'PersonalCenter',
      component: () => import('@/views/personalCenter.vue'),
      name:'PersonalCenter',
      meta: { title: '个人中心', icon: 'UserFilled',menuCode:'personalCenter' },
    }]},
    {
        path:'/deviceManage',
        component: () => import('@/views/layout/Layout.vue'),
        meta: { title: '设备管理', icon: 'Platform',menuCode:'deviceManage'},
        children: [
            {
                path: 'DeviceManagement',
                component: () => import('@/views/deviceManage/DeviceManagement.vue'),
                name: 'DeviceManagement',
                meta: { title: '全部设备管理', icon: 'List',menuCode:'deviceManagement' },
               
            },
            {
                path: 'MyDevice',
                component: () => import('@/views/deviceManage/MyDevice.vue'),
                name: 'MyDevice',
                meta: { title: '我的设备', icon: 'Printer',menuCode:'myDevice' }
            },
            {
                path: 'History',
                name: 'History',
                meta: { title: '设备记录', icon: 'DocumentCopy',menuCode:'history'},
                 children:[
                      {
                          path: 'InspectionList',
                          component: () => import('@/views/deviceManage/history/inspectionManagement.vue'),
                          name: 'InspectionList',
                          meta: { title: '所有巡检历史', icon: 'DataLine',menuCode:'inspectionList' },
                      },{
                        path: 'WarningAndRepair',
                        component: () => import('@/views/deviceManage/history/warningAndRepair.vue'),
                        name: 'WarningAndRepair',
                        meta: { title: '预警和报修', icon: 'Bell',menuCode:'warningAndRepair' }
                    },{
                      path: 'MyDeviceHistoryRecords',
                      component: () => import('@/views/deviceManage/history/MyDeviceHistoryRecords.vue'),
                      name: 'MyDeviceHistoryRecords',
                      meta: { title: '我的设备历史记录', icon: 'el-icon-s-custom',menuCode:'myDeviceHistoryRecords' }
                    }
          ]
            },
           
            
        ]
    },{
    path: '/',
      component: () => import('@/views/layout/Layout.vue'),
      redirect: '/NoticeManage',
      children: [
    {
      path: 'NoticeManage',
      component: () => import('@/views/NoticeManage.vue'),
      name:'NoticeManage',
      meta: { title: '公告管理', icon: 'el-icon-user',menuCode:'noticeManage' },
    }]}

]

// 将前端路由转换为菜单格式
export function generateMenusFromRoutes(routes: RouteRecordRaw[]) {
  return routes.filter(route => {
    //if (route.hidden) return false
    
    const menu: any = {
      path: route.path,
      title: route.meta?.title || '',
      icon: route.meta?.icon || '',
      children: []
    }
    
    if (route.children) {
      menu.children = generateMenusFromRoutes(route.children)
    }
     return menu
  })
}